﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;
using System.Web.Mvc;
using System.Web.Security;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using yeubongda.Models;


/// <summary>
/// Summary description for XL_KH
/// </summary>
public class XL_TK
{
    //protected DataRow Dong;
    protected yeubongda.USER Dong;
    protected static String Tenbang = "USER";
   
    
    public long MTK
    {
        get
        {
            return this.Dong.MAUSER;
        }
        set
        {
            this.Dong.MAUSER = value;
        }
    }
    public string Ten_TK
    {
        get
        {
            return this.Dong.TENUSER;
        }
        set
        {
            this.Dong.TENUSER = value;
        }
    }
    public string Diachi
    {
        get
        {
            return this.Dong.DIACHI.ToString();
        }
        set
        {
            this.Dong.DIACHI = value;
        }
    }
    public string Dienthoai
    {
        get
        {
            return this.Dong.DIENTHOAI.ToString();
        }
        set
        {
            this.Dong.DIENTHOAI = value;
        }
    }
    public byte MLTK
    {
        get
        {
            return (byte)this.Dong.ROLE;
        }
        set
        {
            this.Dong.ROLE = value;
        }
    }
    public Boolean Tinhtrang_TK
    {
        get
        {
            return (Boolean)this.Dong.TINHTRANG;
        }
        set
        {
            this.Dong.TINHTRANG = value;
        }
    }
    public string Email
    {
        get
        {
            return this.Dong.Email.ToString();
        }
        set
        {
            this.Dong.Email = value;
        }
    }
    public string Matkhau_TK
    {
        get
        {
            return this.Dong.Password;
        }
        set
        {
            this.Dong.Password = value;
        }
    }
    public string Hoten
    {
        get
        {
            return this.Dong.Hoten;

        }
        set
        {
            this.Dong.Hoten = value;
        }
    }
        
	
     public XL_TK()
    {
         
                  
        //String sql="select * from TAI_KHOAN";
        //DataTable Bang  = DataProvider.ExecuteStructureQuery(sql);
        
        //Dong = Bang.NewRow();
        //Bang.Rows.Add(Dong);
        List<yeubongda.USER> dsuser = YBDModels.DSUSER();
        Dong = new yeubongda.USER();
        dsuser.Add(Dong);
      
    }

    public XL_TK(yeubongda.USER DongN)
	{
		//
		// TODO: Add constructor logic here
		//
        this.Dong = DongN;
	}

    /*
    public static ArrayList Doc_danh_sach()
    {
        ArrayList Kq = new ArrayList();
        string sql = "Select * ";
        sql += " From " + Tenbang;
        DataTable Bang = DataProvider.ExecuteQuery(sql);
        foreach (DataRow DT in Bang.Rows)
        {
            XL_TK LTK = new XL_TK(DT);
            Kq.Add(LTK);
        }
        return Kq;

    }
    */

    /*
    public static XL_TK TimKH_theo_MS(int MTK)
    {
        
        string sql = "Select * ";
        sql += " From " + Tenbang;
        sql += " Where MTK = " + MTK;

        DataTable Bang = DataProvider.ExecuteQuery(sql);
        if (Bang.Rows.Count>0)
        {
            XL_TK KH = new XL_TK(Bang.Rows[0]);
            return KH;
        }
        return null;

    }

    public static XL_TK TimKH_theo_TenTK(String Ten_TK)
    {
        String sql = "Select * ";
        sql += " From " + Tenbang;
            
        if (Ten_TK != "")
        {
            sql += " Where Ten_TK = '" + XL_SQL.XL_SQL_Attack(Ten_TK) + "'";
        }
        
        DataTable Bang = DataProvider.ExecuteQuery(sql);
        if (Bang.Rows.Count > 0)
        {
            XL_TK KH = new XL_TK(Bang.Rows[0]);
            return KH;
        }
        return null;

    }

    public static ArrayList TimKH_theo_Hoten(String Hoten) // Tim cho phep trung
    {
        ArrayList DS_KH = new ArrayList();
        String sql = "Select * ";
        sql += " From " + Tenbang;


        if (Hoten != "")
        {
            sql += " Where Hoten like '*" + XL_SQL.XL_SQL_Attack(Hoten) + "*'";
        }

        DataTable Bang = DataProvider.ExecuteQuery(sql);
        if (Bang.Rows.Count > 0)
        {
            foreach (DataRow DT in Bang.Rows)
            {
                DS_KH.Add(new XL_TK(DT));
                
            }            
            return DS_KH;
        }
        return null;

    }
    */

    public void Ghi()
    {

        //Ghi Bang
       // DataProvider.Save(this.Dong, Tenbang);
        YBDModels.Ghi(Tenbang, Dong);

    }
    public void Xoa()
    {
        YBDModels.Xoa(Dong);
    }

}

  